package xx.rabbitmq.consumer;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

import static xx.rabbitmq.conf.DeadConfig.DEAD_QUEUE;

@Slf4j
@Component
public class DeadConsumer {

    /**
     *
     * @param msg
     * @param channel
     * @param message
     * @throws IOException
     */
    @RabbitListener(queues = DEAD_QUEUE)
    public void listenerDead(String msg, Channel channel, Message message) throws IOException {
        System.out.println("死信接收到消息" + msg);
        System.out.println("唯一标识:" + message.getMessageProperties().getCorrelationId());
        System.out.println("messageID:" + message.getMessageProperties().getMessageId());
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }


//    /**
//     * 拒绝消息
//     * @param msg
//     * @param channel
//     * @param message
//     * @throws IOException
//     */
//    @RabbitListener(queues = DEAD_QUEUE)
//    public void listenerByBasicReject(String msg, Channel channel, Message message) throws IOException {
//        System.out.println("接收到消息" + msg);
//        channel.basicReject(message.getMessageProperties().getDeliveryTag(), false);
//    }
//
//    /**
//     * 否认消息
//     * @param msg
//     * @param channel
//     * @param message
//     * @throws IOException
//     */
//    @RabbitListener(queues = DEAD_QUEUE)
//    public void listenerByBasicNack(String msg, Channel channel, Message message) throws IOException {
//        System.out.println("接收到消息" + msg);
//        channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
//    }

}
